﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Woodbase.CodeBase.WVR.Objects;
using Microsoft.Http;

namespace WoodbaseVideoRental.Pages.Users
{
    public partial class Create : Woodbase.CodeBase.UI.WoodbaseBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void createUser_Click(object sender, EventArgs ea)
        {
            var user = new User();
            user.GivenName = txbGivenname.Text;
            user.LastName = txbLastname.Text;
            user.Phone = txbPhone.Text;
            user.Street = txbStreetname.Text;
            user.Number = txbStreetnumber.Text;
            user.ZipCode = txbZipcode.Text;
            user.City = txbCity.Text;

            using (HttpClient client = new HttpClient("http://localhost:9090/WVRServices/"))
            {
                var t = HttpContentExtensions.CreateXmlSerializable<User>(user, typeof(User));
                client.TransportSettings.SendChunked = false;
                client.TransportSettings.PreAuthenticate = false;

                using (HttpResponseMessage msg = client.Put("User", t))
                {
                    msg.EnsureStatusIsSuccessful();
                    tblUserForm.Visible = false;
                    responseMsg.Text = "User Created";
                }
            }
        }
    }
}